package org.example.school.service.impl;

import org.example.school.entity.Assignments;
import org.example.school.mapper.AssignmentsMapper;
import org.example.school.service.IAssignmentsService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 作业信息表 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-09-28
 */
@Service
public class AssignmentsServiceImpl extends ServiceImpl<AssignmentsMapper, Assignments> implements IAssignmentsService {
    
    @Override
    public List<Assignments> getAssignmentsByClassId(Integer classId) {
        QueryWrapper<Assignments> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("class_id", classId);
        queryWrapper.orderByDesc("created_at");
        return this.list(queryWrapper);
    }
    
    @Override
    public List<Assignments> getAssignmentsByClassIds(List<Integer> classIds) {
        if (classIds == null || classIds.isEmpty()) {
            return List.of(); // 返回空列表
        }
        
        QueryWrapper<Assignments> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("class_id", classIds);
        queryWrapper.orderByDesc("created_at");
        return this.list(queryWrapper);
    }
}